import 'package:date_format/date_format.dart';

class Convert {
  ///eg.2021-04-02 17:32:35
  static String currentTime() {
    return formatDate(DateTime.now(),
        ['yyyy', '-', 'mm', '-', 'dd', ' ', 'HH', ":", 'nn', ":", "ss"]);
  }

  ///eg.2021-04-02
  static String format(DateTime dateTime) {
    return formatDate(dateTime, ['yyyy', '-', 'mm', '-', 'dd']);
  }

  ///eg.2021-04-02
  static String currentDate() {
    return formatDate(DateTime.now(), ['yyyy', '-', 'mm', '-', 'dd']);
  }

  ///eg.17:32:35
  ///
  ///[second] 是否精确到秒
  static String currentDateTime({bool second = true}) {
    return second
        ? formatDate(DateTime.now(), ['HH', ":", 'nn', ":", "ss"])
        : formatDate(DateTime.now(), ['HH', ":", 'nn']);
  }
}
